//
//  UserVC.swift
//  DollarBuy
//
//  Created by 郑东喜 on 2016/11/7.
//  Copyright © 2016年 郑东喜. All rights reserved.
//

import UIKit

class UserVC: MeBaseViewController {
    //用户名
    @IBOutlet weak var tfNum: UITextField!
    //密码
    @IBOutlet weak var tfPass: UITextField!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
 
}

// MARK:- 跳转接口
extension UserVC {
    //qq登录
    @IBAction func qqLogin(_ sender: UIButton) {
        print("\((#file as NSString).lastPathComponent):(\(#line)):(\("qq登录")))")
        
    }
    
    //微信登录
    @IBAction func wechatLogin(_ sender: UIButton) {
        print("\((#file as NSString).lastPathComponent):(\(#line)):(\("微信登录")))")
    }
    
    
    /**
     恭喜您登录成功
     缺少手机号参数
     帐号与密码不匹配
     */
    //登录
    
    
    @IBAction func loginSEL(_ sender: UIButton) {
        print("\((#file as NSString).lastPathComponent):(\(#line)):(\("单机登陆")))")
        if self.tfNum.text?.characters.count == 0 {
            MBManager.showBriefAlert(tfNumIsNull)
            return

        } else if Encryption.checkTelNumber(self.tfNum.text) == false {
            MBManager.showBriefAlert(tfNumNotCor)
            return
        } else if self.tfPass.text?.characters.count == 0 {
            MBManager.showBriefAlert(tfPassNull)
            
        } else if Encryption.checkTelNumber(self.tfNum.text) == true {
        

            let params = ["phone" : self.tfNum.text as Any,
                          "password" : Encryption.md5Encrypt(with: self.tfPass.text),
                          "deviceid": deviceID,
                          "devtype" : deviceTpye] as [String : Any]
            print(params)
            
//            manager.post(loginUrl, parameters: params, success: { (task, response) in
//                
//                let json = JSON(response:response!)
//                print("\((#file as NSString).lastPathComponent):(\(#line))")
//                print(json)
//                
//                if json["resultmsg"] == "帐号与密码不匹配" {
//                    MBManager.showBriefAlert(passAndAccountNot)
//                } else if json["resultmsg"] == "缺少手机号参数" {
//                    MBManager.showBriefAlert(tfNumNotCor)
//                } else if json["resultmsg"] == "恭喜您登录成功" {
//                    MBManager.showBriefAlert(loginSuccess)
//                }
//                
//            }) { (task, error) in
//                print("\((#file as NSString).lastPathComponent):(\(#line))")
//                print(error)
//            }
//            MBManager.showBriefAlert("登陆中...")
            NetTool.shareInstance.postWithPath(path: loginUrl, paras: params, success: { (response) in
                let json = JSON(response:response)
                print("\((#file as NSString).lastPathComponent):(\(#line))")
                print(json)

                if json["resultmsg"] == "帐号与密码不匹配" {
                    MBManager.hideAlert()
//                    MBManager.showBriefAlert(passAndAccountNot)
                } else if json["resultmsg"] == "缺少手机号参数" {
                    MBManager.hideAlert()
//                    MBManager.showBriefAlert(tfNumNotCor)
                } else if json["resultmsg"] == "恭喜您登录成功" {
                    MBManager.hideAlert()
//                    MBManager.showBriefAlert(loginSuccess)
                }

            }, failure: { (error) in
                print("\((#file as NSString).lastPathComponent):(\(#line))")
                print(error)
                MBManager.showBriefAlert(netWrong)

            })

        }
        
    }
    
    
    
    //注册
    @IBAction func rigSEL(_ sender: UIButton) {
        self.navigationController?.pushViewController(RigisterVC(), animated: true)
        print("\((#file as NSString).lastPathComponent):(\(#line)):(\("跳转注册成功")))")
    }
    
    //重置密码
    @IBAction func resetSEL(_ sender: UIButton) {
        self.navigationController?.pushViewController(ForgetVC(), animated: true)
        print("\((#file as NSString).lastPathComponent):(\(#line)):(\("跳转重置密码成功")))")
    }

}
